import axios from "axios";
import {Notification, MessageBox, Message, Loading} from "element-ui";
import store from "@/store";
import {
  getToken,
} from './auth'
import $C from '@/utils/socketConfig'


export default {

  // get请求
  //封装对应的get请求
  get(url, params={}){
    let cUrl= $C.socketXhrUrl+url
    return new Promise((resolve, reject) => {
      axios.get(cUrl, params)
        .then(res => resolve(res))
        .catch(err => reject(err));
    });
  },
//封装对应的post请求
  post(url, data = {}){
    // console.log('$C.socketXhrUrl', $C.socketXhrUrl)
    let cUrl= $C.socketXhrUrl+url
    let config={
      headers: {Token: getToken() },
    }
    return new Promise((resolve, reject) => {
      axios.post(cUrl, data,config)
        .then(res => {
          console.log('post',res)
          return resolve(res.data.data)
        })
        .catch(err => {
          return reject(err)
          // MessageBox.confirm(
          //   "登录状态已过期，您可以继续留在该页面，或者重新登录",
          //   "系统提示",
          //   {
          //     confirmButtonText: "重新登录",
          //     cancelButtonText: "取消",
          //     type: "warning",
          //   }
          // )
          //   .then(() => {
          //     store.dispatch("LogOut").then(() => {
          //       location.href = "/index";
          //     });
          //   })
          //   .catch(() => {
          //
          //   });
        });
    });
  },



}



